package Request

import "encoding/json"

type UserRequest struct {
	NickName string   `form:"name"`
	Type     int      `form:"type"`
	Tel      string   `form:"cellphone"`
	Enable   string   `form:"enable"`
	CreateAt []string `form:"createAt[]"`
	Page     int      `form:"page"`
	Size     int      `form:"size"`
}

type UserLoginRequest struct {
	UserName string `binding:"required" msg:"请输用户名"  form:"user_name"`
	Password string `binding:"required" msg:"请输入密码"  form:"password"`
}

type Ures struct {
	Name string `form:"name"`
	Url  string ` form:"url"`
}

type UserCreateRequest struct {
	ID         uint       `json:"id"`
	CreateDate int64      `json:"create_date"`
	NickName   string     `binding:"required" msg:"请输入昵称"  json:"nick_name"` // 昵称
	UserName   string     `binding:"required" msg:"请输入用户名" json:"user_name"` // 用户名
	Password   string     `msg:"请输入密码"  json:"password"`                     // 新增修改放一起 手动在创建的时候做验证
	RePassword string     `sg:"请确认密码"  json:"re_password"`
	Avatar     string     `json:"avatar"`
	Imgs       []Ures     `json:"imgs"`
	Email      string     `binding:"required" msg:"请输入email" json:"email"`
	Tel        string     `binding:"required" msg:"请输入电话" json:"tel"`
	Addr       string     `json:"addr"`
	Token      string     `json:"token"`
	IP         string     `json:"ip"`
	Role       uint       `json:"roleId"`
	DepId      uint       `json:"departmentId"`
	SignSource SignSource `json:"sign_source"`
}

type Role uint
type SignSource int

const (
	PermissionAdmin       Role = 1 // 管理员
	PermissionUser        Role = 2 // 普通用户
	PermissionVisitor     Role = 3 // 游客
	PermissionDisableUser Role = 4 // 禁用用户
)

const (
	SingQQ    SignSource = 1 // qq
	SinEmail  SignSource = 2 // email
	SingGitee SignSource = 3 // gitee
)

// MarshalJSON ------------------------ role ------------------------
func (s Role) MarshalJSON() ([]byte, error) {
	return json.Marshal(s.string())
}

func (s Role) string() string {
	var str string
	switch s {
	case PermissionAdmin:
		str = "管理员"
	case PermissionUser:
		str = "用户"
	case PermissionVisitor:
		str = "游客"
	case PermissionDisableUser:
		str = "拔禁用的用户"
	default:
		str = "其他"
	}
	return str
}

// SourceMarshalJSON ------------------------ SignSource ------------------------
func (ss SignSource) SourceMarshalJSON() ([]byte, error) {

	return json.Marshal(ss.SourceString())
}

func (s SignSource) SourceString() string {
	var str string
	switch s {
	case SingQQ:
		str = "qq"
	case SinEmail:
		str = "email"
	case SingGitee:
		str = "gitee"
	default:
		str = "其他"
	}
	return str
}

type UserDelRequest struct {
	Ids []uint `form:"ids"`
}

type UserEditRequest struct {
	Id    uint   `uri:"id" binding:"required" msg:"id"`
	Title string `json:"title" binding:"required" msg:"输入名称"`
}
